﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Navigation;
using TwControlLibrary;
using WPFCustomControls.views;

namespace WPFCustomControls.common
{
    public class PageManager
    {
        private Dictionary<PageEnum, Page> pageDictionary = new Dictionary<PageEnum, Page>();
        public Frame frame;
        private Page currentPage;
        private PageEnum currentPageType;

        public PageManager()
        {

        }

        public PageManager(Frame f)
        {
            this.frame = f;
        }

        private Page GetPageFrame(PageEnum pageId)
        {
            Page page = null;
            if (pageDictionary.ContainsKey(pageId))
            {
                page = pageDictionary[pageId];
            }
            else
            {
                switch(pageId)
                {
                    case PageEnum.IconButtonPage:
                        page = new IconButtonPage();
                        pageDictionary.Add(pageId, page);
                        break;
                    case PageEnum.ColorPickerPage:
                        page = new ColorPickerPage();
                        pageDictionary.Add(pageId, page);
                        break;
                    case PageEnum.ComboBoxPage:
                        page = new ComboBoxPage();
                        pageDictionary.Add(pageId, page);
                        break;
                    case PageEnum.GifImagePage:
                        page = new GifImagePage();
                        pageDictionary.Add(pageId, page);
                        break;
                    case PageEnum.RealTimeChart:
                        page = new RealTimeChartPage();
                        pageDictionary.Add(pageId, page);
                        break;
                    case PageEnum.CloudChart:
                        page = new CloudChartPage();
                        pageDictionary.Add(pageId, page);
                        break;
                    case PageEnum.DataGridPager:
                        page = new DataGridPagerPage();
                        pageDictionary.Add(pageId, page);
                        break;
                    case PageEnum.ProgressRingWinPage:
                        page = new ProgressRingWinPage();
                        pageDictionary.Add(pageId, page);
                        break;
                    default:
                        page = null;
                        break;
                }
            }
            return page;
        }

        public PageEnum GetCurrentPageType()
        {
            return currentPageType;
        }

        public Page GetCurrentPage()
        {
            return currentPage;
        }

        public void Navigate(PageEnum pageId, object extraData = null)
        {
            Page body = GetPageFrame(pageId);
            frame.Navigate(body, extraData);

            this.currentPage = body;
            this.currentPageType = pageId;
        }
    }
}
